package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MeowSalesOrders;
import com.ruoyi.system.service.IMeowSalesOrdersService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 销售订单Controller
 * 
 * @author ruoyi
 * @date 2025-06-24
 */
@Controller
@RequestMapping("/system/orders")
public class MeowSalesOrdersController extends BaseController
{
    private String prefix = "system/orders";

    @Autowired
    private IMeowSalesOrdersService meowSalesOrdersService;

    @RequiresPermissions("system:orders:view")
    @GetMapping()
    public String orders()
    {
        return prefix + "/orders";
    }

    /**
     * 查询销售订单列表
     */
    @RequiresPermissions("system:orders:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MeowSalesOrders meowSalesOrders)
    {
        startPage();
        List<MeowSalesOrders> list = meowSalesOrdersService.selectMeowSalesOrdersList(meowSalesOrders);
        return getDataTable(list);
    }

    /**
     * 导出销售订单列表
     */
    @RequiresPermissions("system:orders:export")
    @Log(title = "销售订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MeowSalesOrders meowSalesOrders)
    {
        List<MeowSalesOrders> list = meowSalesOrdersService.selectMeowSalesOrdersList(meowSalesOrders);
        ExcelUtil<MeowSalesOrders> util = new ExcelUtil<MeowSalesOrders>(MeowSalesOrders.class);
        return util.exportExcel(list, "销售订单数据");
    }

    /**
     * 新增销售订单
     */
    @RequiresPermissions("system:orders:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存销售订单
     */
    @RequiresPermissions("system:orders:add")
    @Log(title = "销售订单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MeowSalesOrders meowSalesOrders)
    {
        return toAjax(meowSalesOrdersService.insertMeowSalesOrders(meowSalesOrders));
    }

    /**
     * 修改销售订单
     */
    @RequiresPermissions("system:orders:edit")
    @GetMapping("/edit/{orderId}")
    public String edit(@PathVariable("orderId") String orderId, ModelMap mmap)
    {
        MeowSalesOrders meowSalesOrders = meowSalesOrdersService.selectMeowSalesOrdersByOrderId(orderId);
        mmap.put("meowSalesOrders", meowSalesOrders);
        return prefix + "/edit";
    }

    /**
     * 修改保存销售订单
     */
    @RequiresPermissions("system:orders:edit")
    @Log(title = "销售订单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MeowSalesOrders meowSalesOrders)
    {
        return toAjax(meowSalesOrdersService.updateMeowSalesOrders(meowSalesOrders));
    }

    /**
     * 删除销售订单
     */
    @RequiresPermissions("system:orders:remove")
    @Log(title = "销售订单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(meowSalesOrdersService.deleteMeowSalesOrdersByOrderIds(ids));
    }
}
